package 矩阵.二维网格迁移;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * TODO
 *
 * @className: ewwgqy
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-05-02 10:49
 **/
public class ewwgqy {
    public static void main(String[] args) {
       int[][] grid = {{1,2,3},{4,5,6},{7,8,9}};
       int k = 1;
        System.out.println(shiftGrid(grid, k));
    }
    public static List<List<Integer>> shiftGrid(int[][] grid, int k) {
        List res = new ArrayList<>();
        int m = grid.length;
        if (m == 0) {
            return res;
        }
        int n = grid[0].length;
        int[][] ans = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                ans[(i + (j + k) / n) % m][(j + k) % n] = grid[i][j];
            }
        }
        res = Arrays.asList(ans);
        return res;
    }
}
